﻿using CefSharp;
using System;

namespace QWManage.Utils
{
    public class LifeSpanHandler : ILifeSpanHandler
    {
        public event Action<string> PopupRequest;
        bool ILifeSpanHandler.DoClose(IWebBrowser browserControl, IBrowser browser)
        {
            return false;
        }

        void ILifeSpanHandler.OnAfterCreated(IWebBrowser browserControl, IBrowser browser)
        {
        }

        void ILifeSpanHandler.OnBeforeClose(IWebBrowser browserControl, IBrowser browser)
        {

        }

        bool ILifeSpanHandler.OnBeforePopup(
            IWebBrowser browserControl,
            IBrowser browser,
            IFrame frame,
            string targetUrl,
            string targetFrameName,
            WindowOpenDisposition targetDisposition,
            bool userGesture,
            IPopupFeatures popupFeatures,
            IWindowInfo windowInfo,
            IBrowserSettings browserSettings,
            ref bool noJavascriptAccess,
            out IWebBrowser newBrowser)
        {
            if (PopupRequest != null)
            {
                PopupRequest(targetUrl);
            }
            newBrowser = null;
            return true;//do not pop
        }
    }
}
